package com.headwind.quartz;


import com.headwind.entity.HwUser;
import com.headwind.mail.SendJunkMailService;
import com.headwind.service.HwUserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Headwind
 * @version : 1.0
 * @date : Created in 2020/8/10
 * @description : 定时器类
 */
@Component
@Configurable
@EnableScheduling
public class SendMailQuartz {

    /**
     * 日志对象
     */

    private static final Logger logger = LogManager.getLogger(SendMailQuartz.class);

    @Resource
    private SendJunkMailService sendJunkMailService;
    @Resource
    private HwUserService userService;


    /**
     * 每5秒执行一次
     */
    @Scheduled(cron = "*/5 * *  * * * ")
    public void reportCurrentByCron() {
        List<HwUser> userList = userService.findAllUser();
        if (userList == null || userList.size() <= 0) {
            return;
        }
        //发送邮件
        sendJunkMailService.sendJunkMail(userList);
        logger.info("定时器运行了!!!");

    }

}
